package oop.ex1.actions;

import java.io.File;

/**
 * a subclass that changes a file executable option to a selected one.	
 * @author danalmog
 * @author danielshalev
 */
public class Exec extends Actions {
	private boolean permision;
	private File file;
	
	/**
	 * construct a new exec action, save's the user choice as boolean 
	 * @param permision the desired state which the user wants
	 * @param file the file to change
	 * @throws ActionYesNoExeption indicates the parameter that was entered is not yes/no 
	 */
	public Exec(String permision,File file) throws ActionYesNoExeption{
		super(file);
		this.file=file;
		//checks and sets the desired permission
		if(permision.equals("YES"))
			this.permision=true;
		else if(permision.equals("NO"))
			this.permision=false;
		else 
			throw new ActionYesNoExeption();
	}
	
	/**
	 * changes the executable permissions 
	 */
	public void doAction(){
		file.setExecutable(permision);
	}
}

